Android LiveData
LiveData is:
an observable data holder class
lifecycle-aware, meaning it respects the lifecycle of other app components, such as activities, fragments, or services
LiveData Overview  |  Android Developers
#Android_viewModel #Observer_pattern
LiveDataの基礎的な性質を整理する。 - Qiita
【Android Architecture Components】LiveData 和訳 - Qiita
transformationへの解説(和訳)もある
LiveDataが nullableになることについては、 通常は、!!で対処するけど、、
android - Nullability and LiveData with Kotlin - Stack Overflow
a. Collection, Stringのときは、.orEmpty()を使う(他の型のときは同様なメソッド?)
b. LiveDataを継承したクラスを作る
NonNullとして扱えるAndroid Architecture ComponentsのLiveDataを作る - Qiita
こちらに詳しく書いてある。が、未だ自分は追えてない。
NonNull LiveData with Kotlin extension - ProAndroidDev
Single LiveEvent Case
LiveData with SnackBar, Navigation and other events (the SingleLiveEvent case)
like a Snackbar message, a navigation event or a dialog trigger. data should be consumed only once
どうやって実装するか。
viewmodel側に専用flag, 確実でない。
observer側で条件判定、煩雑
SingleLiveEvent<Any>()を viewModelのメンバーにして、監視対象にする。
observerは1人(箇所)のみに制限される
監視する値を Event的なclassにする?
This method models the events as part of the state
一度だけ通知するAndroid Architecture ComponentsのLiveDataを作る - Qiita
こちらのがよいかな。後から気づいた。
#Android_Activity #Android_Fragment